package
{
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.system.Security;
	
	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Apr 10, 2012 5:45:57 PM 
	 */ 
	public class InitZombieTown extends Sprite
	{
//		[Embed(source="../bin-release/ZombieTown.swf", mimeType="application/octet-stream")]
		[Embed(source="../bin-debug/ZombieTown.swf", mimeType="application/octet-stream")]

		public var _main:Class;
		public var _isLoader:Boolean;
		public var callback:Function;
		
		public function InitZombieTown()
		{
			Security.allowDomain("*");
		}
		
		/**
		 * 启动加载 
		 */		
		public function start():void{
			var loadContext:LoaderContext = new LoaderContext();
			loadContext.applicationDomain = ApplicationDomain.currentDomain;
			var loader:Loader=new Loader();
			loader.loadBytes(new _main(),loadContext);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
		}
		
		/**
		 * 加载完成 
		 * @param evt
		 */		
		private function loadComplete(evt:Event):void{
			var info:LoaderInfo = LoaderInfo(evt.target);
			var domain:ApplicationDomain = info.applicationDomain;
			_main = domain.getDefinition("ZombieTown") as Class;
			_isLoader = true;
			this.callback(_main);
			this.callback = null;
		}
	}
}
